/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PodnosenjeZahtjevaGOPanel.java
 *
 * Created on Nov 23, 2010, 1:06:41 PM
 */

package hraplication;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author Nermin
 */
public class PodnosenjeZahtjevaGOPanel extends Paneli {
    int idUposlenika;
    Konekcija kon;
    /** Creates new form PodnosenjeZahtjevaGOPanel */
    public PodnosenjeZahtjevaGOPanel(Konekcija konekcija) {
        initComponents();
        kon = konekcija;
        idUposlenika = 0;
    }

    public void setIDuposlenika(int IDuposlenika){
        idUposlenika = IDuposlenika;
    }

    public void OsvjeziChBOX(){
               
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        datumPocetkaField = new javax.swing.JTextField();
        datumKrajaField = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        napomenaText = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        jTextField1.setName("jTextField1"); // NOI18N

        setBorder(javax.swing.BorderFactory.createTitledBorder("Zahtjev za godisnji odmor"));
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(hraplication.HRaplicationApp.class).getContext().getResourceMap(PodnosenjeZahtjevaGOPanel.class);
        datumPocetkaField.setToolTipText(resourceMap.getString("datumPocetkaField.toolTipText")); // NOI18N
        datumPocetkaField.setName("datumPocetkaField"); // NOI18N

        datumKrajaField.setToolTipText(resourceMap.getString("datumKrajaField.toolTipText")); // NOI18N
        datumKrajaField.setName("datumKrajaField"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        napomenaText.setColumns(20);
        napomenaText.setRows(5);
        napomenaText.setName("napomenaText"); // NOI18N
        jScrollPane1.setViewportView(napomenaText);

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(datumKrajaField, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(datumPocetkaField, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(datumPocetkaField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(datumKrajaField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        InsertZahtjeva();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void InsertZahtjeva(){
        // kupiti id korisnika koji je trenutno logovan
        // dok se ta funkcionalnost ne napravi ID uposlenika se bira u listi
        
        
        if (datumKrajaField.getText().equals("") || datumPocetkaField.getText().equals("")){
                JOptionPane.showMessageDialog(this, "Unesite sva polja", "Info",WIDTH,null);
                return;
        }
        
        try {
            String datumPocetka = "STR_TO_DATE('" + datumPocetkaField.getText()+ "', '%d.%m.%Y')";
            String datumZavrsetka = "STR_TO_DATE('" + datumKrajaField.getText()+ "', '%d.%m.%Y')";
            String ins = "INSERT INTO zahtjev_za_go (Uposlenici_idUposlenici,Datum_pocetka, Datum_zavrsetka, Napomena, status) VALUES(";
            ins = ins + idUposlenika + "," + datumPocetka + "," + datumZavrsetka + ",'" + napomenaText.getText() + "','PODNESEN')";

            String greska = kon.Insert(ins);
            if (greska != null)
                //DOSLO DO GRESKE
                JOptionPane.showMessageDialog(this, greska, "Greska",WIDTH,null);
            else{
                datumPocetkaField.setText("");
                datumKrajaField.setText("");
                napomenaText.setText("");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField datumKrajaField;
    private javax.swing.JTextField datumPocetkaField;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextArea napomenaText;
    // End of variables declaration//GEN-END:variables

}
